package com.mia.props.client.renderers;

import com.mia.craftstudio.libgdx.Vector3;
import com.mia.craftstudio.minecraft.client.CSClientModelWrapperVBO;
import com.mia.props.Props;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;
import org.lwjgl.opengl.GL11;

public class RenderToolInv implements IItemRenderer {
   private float rotationAngle;
   private Vector3 rotationVector;
   private Vector3 preRotataionTranslation;
   private Vector3 postRotataionTranslation;
   private final Vector3 entityHeightOffset = new Vector3(0.0F, 0.3F, 0.0F);
   private final Vector3 entityAlignmentOffset = new Vector3(-0.5F, -0.04F, -0.5F);
   private final Vector3 equippedRotation = new Vector3(0.5F, 1.0F, 0.0F);
   private final Vector3 equippedAlignmentOffset = new Vector3(-0.25F, 0.25F, -0.3F);
   private final Vector3 inventoryAlignmentOffset = new Vector3(-0.15F, 0.0F, -0.1F);

   public boolean handleRenderType(ItemStack item, ItemRenderType type) {
      return true;
   }

   public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
      return true;
   }

   public void renderItem(ItemRenderType type, ItemStack itemstack, Object... data) {
      GL11.glPushMatrix();
      if (type == ItemRenderType.ENTITY) {
         this.rotationAngle = 90.0F;
         this.rotationVector = Vector3.invX;
         this.preRotataionTranslation = this.entityHeightOffset;
         this.postRotataionTranslation = this.entityAlignmentOffset;
      } else if (type == ItemRenderType.EQUIPPED) {
         this.rotationAngle = 228.0F;
         this.rotationVector = this.equippedRotation;
         this.preRotataionTranslation = Vector3.halfXZ;
         this.postRotataionTranslation = this.equippedAlignmentOffset;
      } else if (type == ItemRenderType.INVENTORY) {
         this.rotationAngle = 195.0F;
         this.rotationVector = Vector3.Y;
         this.preRotataionTranslation = Vector3.halfXZ;
         this.postRotataionTranslation = this.inventoryAlignmentOffset;
         GL11.glScalef(1.5F, 1.5F, 1.5F);
      } else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) {
         this.rotationAngle = -80.0F;
         this.rotationVector = Vector3.X;
         this.preRotataionTranslation = Vector3.halfXZ;
         this.postRotataionTranslation = Vector3.Zero;
         GL11.glTranslatef(0.5F, 0.0F, 0.5F);
         GL11.glRotatef(125.0F, 0.166667F, 1.0F, 0.0F);
         GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
      } else {
         this.rotationAngle = 0.0F;
         this.rotationVector = Vector3.Zero;
         this.preRotataionTranslation = Vector3.Zero;
         this.postRotataionTranslation = Vector3.Zero;
      }

      ((CSClientModelWrapperVBO)Props.itemTool.modelMeta.wrapper).render(data, 0.0F, 2, false, this.rotationAngle, this.rotationVector, this.preRotataionTranslation, this.postRotataionTranslation);
      GL11.glPopMatrix();
   }
}
